package org.project.d.network.exception;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

import java.util.Collection;
import java.util.List;

/**
 * @author lin
 * @version V1.0
 * @description
 * @date 2020/10/8 4:00 下午
 */
public class BusinessProcessingExceptionHandlerManager {
    private static final Multimap<Short, BusinessProcessingExceptionHandler> businessProcessingsMap = ArrayListMultimap.create();
    private static final List<BusinessProcessingExceptionHandler> businessProcessings=Lists.newArrayList();
    public static boolean addBusinessProcessingExceptionHandler(Short k, BusinessProcessingExceptionHandler v) {
        if (v == null) {
            throw new RuntimeException("addBusinessProcessingExceptionHandler v must not null");
        }
        if (k==null){
            return businessProcessings.add(v);
        }
        return businessProcessingsMap.put(k, v);
    }

    public static Collection<BusinessProcessingExceptionHandler> getBusinessProcessingExceptionHandler(Short k){
        if (k==null){
            return businessProcessings;
        }
        Collection<BusinessProcessingExceptionHandler> businessProcessingExceptionHandlers = businessProcessingsMap.get(k);
        if (businessProcessingExceptionHandlers.size()<1){
            return businessProcessings;
        }
        return businessProcessingExceptionHandlers;
    }

    public static boolean addBusinessProcessingExceptionHandler(BusinessProcessingExceptionHandler businessProcessingExceptionHandler) {
        return addBusinessProcessingExceptionHandler(null,businessProcessingExceptionHandler);
    }
}
